package iss.anxios.controller;

import java.util.HashMap;
import java.util.Map;

import iss.anxios.dto.MenuItem;
import iss.anxios.service.MenuItemService;
import iss.anxios.service.RespondentService;
import iss.anxios.service.RespondentTypeService;
import iss.anxios.service.ViewGroupService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/menuitemcontroller")
public class MenuItemController {

	@Autowired
	private MenuItemService menuitemservice;
	@Autowired
	private ViewGroupService viewgroupservice;
	@Autowired
	private RespondentService respondentservice;
	@Autowired
	private RespondentTypeService respondenttypeservice;
	
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ModelAndView saveMenuItem (@ModelAttribute("menuitem") MenuItem  menuitem,
			BindingResult result) {
		menuitemservice.addMenuItem(menuitem);
		return new ModelAndView("redirect:/menuitemcontroller.html");
	}

	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView listMenuItem() {
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("menuitemcontroller",  menuitemservice.listMenuItems());
		model.put("viewgroupcontroller", viewgroupservice.lisViewGroups());
		model.put("respondentcontroller", respondentservice.ListRespondent());
		model.put("respondenttypecontroller", respondenttypeservice.ListRespondentType());
		
		System.out.println("I am in controller");
		return new ModelAndView("MenuItemList", model);
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public ModelAndView addMenuItem(@ModelAttribute("menuitem") MenuItem  menuitem,
			BindingResult result) {
		return new ModelAndView("MenuItemList");
	}
	
}
